﻿//添加cookie 
function addCookie(name, value, expires, path, domain) {
    var str = name + "=" + escape(value);
    if (expires != null) {
        var date = new Date();
        date.setTime(date.getTime() + expires * 24 * 3600 * 1000); //expires单位为天 
        str += ";expires=" + date.toGMTString();
    }
    if (path != null) {
        str += ";path=" + path; //指定可访问cookie的目录 
    }
    if (domain != null) {
        str += ";domain=" + domain; //指定可访问cookie的域 
    }
    document.cookie = str;
}
//取得cookie 
function getCookie(name) {
    var str = document.cookie.split(";")
    for (var i = 0; i < str.length; i++) {
        var str2 = str[i].split('=');
        if (str2[0] == name)
            return unescape(str2[1]);
    }
}
//删除cookie 
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}